package org.jason.article.mq.consumer;

import org.jason.article.service.ICaArticleService;
import org.jason.model.interaction.dtos.ArticleInteractionDto;
import org.jason.model.article.dtos.ContributeDto;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class ArticleConsumer {

    @Autowired
    private ICaArticleService articleService;

    //从队列接受投稿并上传
    @RabbitListener(queues = "contribute.queue")
    public void contributeArticle(ContributeDto dto) {
        articleService.saveArticle(dto);
    }

    //文章互动
    @RabbitListener(queues = "article.behavior.queue")
    public void articleInteraction(ArticleInteractionDto dto) {
        articleService.interaction(dto, false);
    }

    //取消文章互动
    @RabbitListener(queues = "article.cancel.queue")
    public void cancelArticleInteraction(ArticleInteractionDto dto) {
        articleService.interaction(dto, true);
    }
}
